<template>
	<view class="page">
		<!-- 地址 -->
		<view class="address-data">
			<view class="address-list" @tap='onAddress'>
				<view  v-if="addressInfo">
					<view class="list">
						<text>{{addressInfo.province}}{{addressInfo.city}}{{addressInfo.area}}</text>
					</view>
					<view class="list">
						<text class="address">{{addressInfo.address}}</text>
					</view>
					<view class="list">
						<text>{{addressInfo.name}}</text>
						<text>{{addressInfo.phone}}</text>
					</view>
					<view class="list">
						<text class="tips">(如果快递不方便接收，您可以选择暂时寄存服务)</text>
					</view>
				</view>
				<view class="flex flex-align flex-bt" v-else style="padding-bottom: 30rpx;">
					<view class="left" >设置收货地址</view>
					<view class="rigth">
						<tui-icon name="arrowright" :size="24" color="#999"></tui-icon>
					</view>
				</view>
			</view>
			<view class="bar">

			</view>
		</view>
		<!-- 商品 -->
		<view class="goods-data">
			<view class="goods-title">
				<text>商品信息</text>
			</view>
			<view class="goods-list">
				<view class="list" v-for="(item,index) in order" :key="index">
					<view class="thumb">
						<image :src="item.goods_cover" mode=""></image>
					</view>
					<view class="item">
						<view class="title">
							<text class="name one-omit">{{item.goods_name}}</text>
							<text class="attr">{{item.goods_spec}}</text>
						</view>
						<view class="price-number">
							<view class="price">
								<text class="min">￥</text>
								<text class="max">{{item.price_selling}}</text>
							</view>
							<view class="number">
								<text>x {{item.stock_sales}}</text>
							</view>
						</view>
						<!-- <view class="tag">
							<text>支持七天无理由退货</text>
						</view> -->
					</view>
				</view>
			</view>
			<view class="delivery">
				<div class="list">
					<view class="title">配送</view>
					<view class="content">
						<text>快递运输</text>
						<text class="iconfont icon-more"></text>
					</view>
				</div>
				<div class="list">
					<view class="title">运费险</view>
					<view class="content">
						<text>￥0.00</text>
					</view>
				</div>
				<div class="list">
					<view class="title">留言</view>
					<view class="content">
						<input type="text" placeholder="选填,建议先和商家沟通确认">
					</view>
				</div>
			</view>
		</view>
		<!-- 优惠 -->
		
		<!-- 订单金额 -->
		<view class="order-price">
			<view class="price-list">
				<view class="list">
					<view class="title">
						<text>商品金额</text>
					</view>
					<view class="price">
						<text>￥{{dataInfo.amount_real}}</text>
					</view>
				</view>
				<view class="list">
					<view class="title">
						<text>运费</text>
					</view>
					<view class="price">
						<text class="highlight">+￥0.00</text>
					</view>
				</view>
				<view class="list" @click="openQuan" v-if="dataInfo.goods_type==1">
					<view class="title">
						<text>优惠券</text>
					</view>
					<view class="price">
						<text v-if="quanInfo.length==0" class="" style="color: #999;font-weight: 300;">暂无可用优惠券</text>
						<text style="color: #f20;">{{yhqContent}}</text>
						<tui-icon name="arrowright" :size="24" color="#333"></tui-icon>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部合计提交 -->
		<view class="footer-submit">
			<view class="price">
				<text class="min">￥</text>
				<text class="max">{{count}}</text>
			</view>
			<view class="submit" @click="onSubmit">
				<text>提交订单</text>
			</view>
		</view>
		<!-- 发票 -->
		<!-- 优惠券 -->
		<use-coupon ref="UseCoupon" :data="quanInfo" @finish="getyhq"></use-coupon>
	</view>
</template>

<script>
	import UseCoupon from '../../components/UseCoupon/UseCoupon.vue'
	export default {
		components: {
			// 优惠券
			UseCoupon,
		},
		data() {
			return {
				scrollTop: 0,
				addressInfo:'',
				code:'',
				dataInfo:'',
				order:[],
				quanInfo:[],
				yhqContent:'',
				yhqInfo:'',
				count:0
			};
		},
		onPageScroll(e){
			this.scrollTop = e.scrollTop;
		},
		onLoad(e) {
			this.code =e.order_no
			
		},
		onShow() {
			this.getAddress()
			this.get_data()
		},
		methods:{
			/**
			 * 提交订单
			 */
			onSubmit(){
				let that = this
				if(!that.addressInfo){
					that.tui.toast('请设置收货地址')
					setTimeout(function(){
						uni.navigateTo({
							url:'/pages/AddressEdit/AddressEdit'
						})
					},1000)
					return false
				}
				uni.redirectTo({
					url: '/pages/CashierDesk/CashierDesk?code='+this.code+"&&price="+this.count+"&&addresscode="+that.addressInfo.code+"&coupon_id="+this.yhqInfo.id,
				})
			},
			getyhq(e){
				console.log(e)
				if(e){
					this.yhqContent = '满'+e.full_price+'元减'+e.price+'元'
					this.yhqInfo = e
					this.count = (this.dataInfo.amount_real-e.price).toFixed(2)
				}else{
					this.yhqContent =''
					this.count = this.dataInfo.amount_real
				}
				
			},
			openQuan(){
				if(this.quanInfo.length==0){
					return
				}
				this.$refs['UseCoupon'].show()
			},
			getQuan(){
				let that = this
				that.tui.request("api.auth.order/couponOrderList", "GET", {price:that.dataInfo.amount_real}, false,false, true).then((res) => {
					that.quanInfo = res.data.list
				}).catch((res) => {})
			},
			getAddress(){
				let that = this
				that.tui.request("api.auth.address/get", "GET", {page:1}, false,false, true).then((res) => {
					that.addressInfo = res.data.list[0]
				}).catch((res) => {})
			},
			get_data(){
				let that = this
				that.tui.request("api.auth.order/orderDetail", "post", {order_no:that.code}, false, true, false).then((res) => {
					console.log(res)
					that.dataInfo = res.data.info
					that.order = res.data.info.order
					that.count = res.data.info.amount_real
					that.getQuan()
				}).catch((res) => {})
			},
			onAddress() {
				if(this.addressInfo){
					uni.navigateTo({
						url: '/pages/AddressList/AddressList'
					})
				}else{
					uni.navigateTo({
						url: '/pages/AddressEdit/AddressEdit'
					})
				}
			},
      /**
       * 跳转点击
       * @param {String} type 跳转类型
       */
      onSkip(type){
        switch (type){
          case 'address':
            uni.navigateTo({
              url: '/pages/AddressList/AddressList',
            })
            break;
        }
      }
		}
	}
</script>

<style scoped lang="scss">
	@import 'ConfirmOrder.scss';
</style>
